package com.miplus.ccrm.core.service.aicall;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.core.controller.vo.aicall.ObCallHistResVo;
import com.miplus.ccrm.core.controller.vo.aicall.ObCallListReqVo;
import com.miplus.ccrm.core.controller.vo.aicall.ObCallListResVo;
import com.miplus.ccrm.core.pojo.ObCallCase;
import com.miplus.ccrm.core.pojo.ObCallHist;
import com.miplus.ccrm.core.mapper.ObCallHistMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author pc
* @description 针对表【OB_CALL_HIST(AI外呼数据表)】的数据库操作Service实现
* @createDate 2024-10-30 17:53:46
*/
@Service
public class ObCallHistServiceImpl extends MPJBaseServiceImpl<ObCallHistMapper, ObCallHist>
    implements ObCallHistService{

    @Override
    public List<ObCallHistResVo> dialHist(Long caseid)
    {
        return selectJoinList(ObCallHistResVo.class,
                new MPJLambdaWrapper<ObCallHist>()
                        .leftJoin(ObCallCase.class, "oc",ObCallCase::getCaseid, ObCallHist::getCaseid)
                        .selectAs(ObCallHist::getStatus,ObCallHistResVo::getPdstatus)
                        .selectAs(ObCallCase::getPdCalllist,ObCallHistResVo::getClid)
                        .selectAs(ObCallHist::getCcc,ObCallHistResVo::getCcc)
                        .selectAs("fun_getnames('CAMPAIGN.CB.STATUS',t.status)",ObCallHistResVo::getPdstatusdesc)
                        .selectAs("(select cp.name from cp_calllist cp where cp.clid=oc.pd_calllist)", ObCallHistResVo::getClname)
                        .selectAs("(select cs.helpstr from cp_strategy cs where cs.clid = oc.pd_calllist and cs.ccc = t.ccc)",ObCallHistResVo::getCccdsc)
                        .selectAs(ObCallHist::getDialcnt, ObCallListResVo::getDialcnt)
                        .selectAs(ObCallHist::getCallid,ObCallHistResVo::getCallcaseid)
                        .selectAs(ObCallHist::getCaseid,ObCallHistResVo::getCaseid)
                        .selectAs("r.filename",ObCallHistResVo::getRecurl)
                        .leftJoin("t_recorder r on r.callid=t.callid")
                        .select(ObCallHist::getId,ObCallHist::getDialdt,ObCallHist::getDialspan,ObCallHist::getConnectspan,ObCallHist::getQueuespan)
                        .eq(ObCallHist::getCaseid, caseid)
                        .orderByDesc(ObCallCase::getDialdt)
        );
    }
}




